<?php /*a:2:{s:74:"D:\phpstudy_pro\WWW\www.xnadmin.site\app\admin\view\data_project\form.html";i:1623403040;s:63:"D:\phpstudy_pro\WWW\www.xnadmin.site\app\admin\view\iframe.html";i:1588058566;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?php echo xn_cfg('base.sys_name'); ?></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script>
        //全局上传文件端口
        var UPLOAD_FILE_URL = "<?php echo url('upload_files/upload'); ?>";
        //全局选择文件端口
        var SELECT_FILE_URL = "<?php echo url('upload_files/select'); ?>";
    </script>
    <script src="/static/admin/js/jquery-2.0.0.min.js"></script>
    <script src="/static/admin/js/common.js"></script>
    <script src="/static/admin/js/upload.js"></script>
    <script src="/static/admin/js/webuploader.min.js"></script>
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/style/base.css" media="all">
    
    <style>
        .h15{height: 15px;}
    </style>
</head>
<body>
<div class="h15"></div>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form action="<?php echo request()->url(); ?>" method="post" class="xn_ajax2" data-type="open">
        <div class="layui-form-item">
            <label class="layui-form-label">行业类型</label>
            <div class="layui-input-inline">
                <select name="parent_typeid" lay-filter="parent_typeid" id="parent_typeid">
                    <option value="0">选择类型</option>
                    <?php if(is_array($parent_typelist) || $parent_typelist instanceof \think\Collection || $parent_typelist instanceof \think\Paginator): if( count($parent_typelist)==0 ) : echo "" ;else: foreach($parent_typelist as $key=>$vo): ?>
                    <option value="<?php echo htmlentities($vo['id']); ?>" <?php if($data['parent_typeid'] == $vo['id']): ?>selected<?php endif; ?> ><?php echo htmlentities($vo['title']); ?></option>
                    <?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="typeid" id="typeid">
                    <option value="0">选择类型</option>
                    <?php if(is_array($typelist) || $typelist instanceof \think\Collection || $typelist instanceof \think\Paginator): if( count($typelist)==0 ) : echo "" ;else: foreach($typelist as $key=>$vo): ?>
                    <option value="<?php echo htmlentities($vo['id']); ?>" <?php if($data['typeid'] == $vo['id']): ?>selected<?php endif; ?> ><?php echo htmlentities($vo['title']); ?></option>
                    <?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" id="project" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['title']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目别称</label>
            <div class="layui-input-block">
                <input type="text" name="alias" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['alias']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-block">
                <input type="text" name="company" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['company']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">广告语</label>
            <div class="layui-input-block">
                <input type="text" name="slogan" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['slogan']); ?>">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">项目摘要</label>
            <div class="layui-input-block">
                <textarea name="description" class="layui-textarea"><?php echo htmlentities($data['description']); ?></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">加盟费(最低)</label>
            <div class="layui-input-block">
                <input type="text" name="cost_min" class="layui-input" value="<?php echo htmlentities($data['cost_min']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">加盟费(最高)</label>
            <div class="layui-input-block">
                <input type="text" name="cost_max" class="layui-input" value="<?php echo htmlentities($data['cost_max']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌源地</label>
            <div class="layui-input-block">
                <input type="text" name="origin" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['origin']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">主营类目</label>
            <div class="layui-input-block">
                <input type="text" name="business" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['business']); ?>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">门店数量</label>
            <div class="layui-input-block">
                <input type="text" name="shop_num" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['shop_num']); ?>">
            </div>
        </div>
        <!-- <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">项目介绍</label>
            <div class="layui-input-block">
                <textarea name="content" class="layui-textarea"><?php echo htmlentities($data['content']); ?></textarea>
            </div>
        </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label">项目介绍</label>
            <div class="layui-input-block">
                <blockquote class="layui-elem-quote layui-quote-nm">
                    <div class="layui-form-item">
                        <button type="button" class="layui-btn" onclick="addDiv()">增加</button>
                    </div>
                    <div id="box">
                        <?php if(is_array($contentlist) || $contentlist instanceof \think\Collection || $contentlist instanceof \think\Paginator): if( count($contentlist)==0 ) : echo "" ;else: foreach($contentlist as $key=>$vo): ?>
                        <div class="layui-form-item layui-form-text">
                            <textarea class="layui-textarea" data-id="<?php echo htmlentities($vo['id']); ?>"><?php echo htmlentities($vo['content']); ?></textarea>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="editContent(this)">修改</button>
                            <button type="button" class="layui-btn layui-btn-danger" onclick="deleteContent(this)">删除</button>
                        </div>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                    </div>
                </blockquote>
            </div>
        </div>
        
        
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" lay-submit class="layui-btn">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>


<script src="/static/admin/layui/layui.all.js"></script>
<script src="/static/admin/js/admin.js"></script>

<script>
    var form = layui.form;
    form.on('select(parent_typeid)', function(res) { 
        $("#typeid").empty();
        if(res.value != 0){
            $.get("<?php echo url('admin/DataType/getSonType'); ?>?pid="+res.value,function(result){
                if(result.status){
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#typeid").append(new Option(item.title,item.id));
                    });
                    form.render("select");
                }
            });
        }else{
            $("#typeid").append(new Option('请选择',0));
            form.render("select");
        }
    })

    function addDiv(){
        var html = getHtml();
        $('#box').append(html)
    }
    function getHtml(){
        var html = '<div class="layui-form-item layui-form-text">\
                        <textarea class="layui-textarea"></textarea>\
                        <button type="button" class="layui-btn layui-btn-normal" onclick="saveContent(this)">保存</button>\
                        <button type="button" class="layui-btn layui-btn-danger" onclick="removeDiv(this)">移除</button>\
                    </div>';
        return html;
    }
    function removeDiv(obj){
        $(obj).parent().remove();
    }

    function saveContent(obj){
        var content = $(obj).prev().val();
        if(content == ''){
            layer.msg('不能为空', {icon: 2,time: 1500});
            return;
        }
        var parent_typeid = $('#parent_typeid').val();
        var typeid = $('#typeid').val();
        var project = $('#project').val();
        $.post("<?php echo url('DataProjectContent/add'); ?>",{parent_typeid:parent_typeid,typeid:typeid,project:project,content:content},function(res){
            layer.msg(res.msg, {time: 1500});
            if(res.code){
                location.reload();
            }
        });
    }

    function editContent(obj){
        var id = $(obj).prev().attr('data-id');
        var content = $(obj).prev().val();
        if(id == '' || id == 0){
            layer.msg('参数错误', {icon: 2,time: 1500});
            return;
        }
        if(content == ''){
            layer.msg('不能为空', {icon: 2,time: 1500});
            return;
        }
        var parent_typeid = $('#parent_typeid').val();
        var typeid = $('#typeid').val();
        var project = $('#project').val();
        $.post("<?php echo url('DataProjectContent/edit'); ?>",{id:id,parent_typeid:parent_typeid,typeid:typeid,project:project,content:content},function(res){
            layer.msg(res.msg, {time: 1500});
        });
    }

    function deleteContent(obj){
        var id = $(obj).prev().prev().attr('data-id');
        if(id == '' || id == 0){
            layer.msg('参数错误', {icon: 2,time: 1500});
            return;
        }
        $.get("<?php echo url('DataProjectContent/delete'); ?>",{id:id},function(res){
            layer.msg(res.msg, {time: 1500});
            if(res.code){
                $(obj).parent().remove();
            }
        });
    }
</script>

</body>
</html>